package repository

import (
	"hcy-api/structs/tables"
	"idp/global"
)

var WinLogRepository = new(winLogRepository)

type winLogRepository struct{}

func (r winLogRepository) SaveLogCpu(m *tables.IdpLogCpu) (err error) {
	return global.DB.Save(m).Error
}
func (r winLogRepository) FindLastCpu(id int64) (m tables.IdpLogCpu, err error) {
	err = global.DB.Where("client_id = ? ", id).
		Order("created_at desc").Limit(1).Find(&m).Error
	return
}
func (r winLogRepository) SaveLogMemory(m *tables.IdpLogMemory) (err error) {
	return global.DB.Save(m).Error
}

func (r winLogRepository) FindLastMemory(id int64) (m tables.IdpLogMemory, err error) {
	err = global.DB.Where("client_id = ? ", id).
		Order("created_at desc").Limit(1).Find(&m).Error
	return
}

func (r winLogRepository) SaveLogDisk(m *tables.IdpLogDisk) (err error) {
	return global.DB.Save(m).Error
}

func (r winLogRepository) FindLastDisk(id int64) (m tables.IdpLogDisk, err error) {
	err = global.DB.Where("client_id = ? ", id).
		Order("created_at desc").Limit(1).Find(&m).Error
	return
}

func (r winLogRepository) SaveLogBoard(m *tables.IdpLogBoard) (err error) {
	return global.DB.Save(m).Error
}

func (r winLogRepository) FindLastBoard(id int64) (m tables.IdpLogBoard, err error) {
	err = global.DB.Where("client_id = ? ", id).
		Order("created_at desc").Limit(1).Find(&m).Error
	return
}

func (r winLogRepository) SaveLogSysAbstract(m *tables.IdpLogSysAbstract) (err error) {
	return global.DB.Save(m).Error
}
func (r winLogRepository) FindLastSysAbstract(id int64) (m tables.IdpLogSysAbstract, err error) {
	err = global.DB.Where("client_id = ? ", id).
		Order("created_at desc").Limit(1).Find(&m).Error
	return
}

func (r winLogRepository) SaveLogApp(m *tables.IdpLogApp) (err error) {
	return global.DB.Save(m).Error
}

func (r winLogRepository) FindLastApp(id int64) (m tables.IdpLogApp, err error) {
	err = global.DB.Where("client_id = ? ", id).
		Order("created_at desc").Limit(1).Find(&m).Error
	return
}

func (r winLogRepository) SaveAppChangeLog(li []tables.IdpAppChangeLog) (err error) {
	return global.DB.Save(&li).Error
}
